/*     */ import java.awt.BorderLayout;
/*     */ import java.awt.Color;
/*     */ import java.awt.Font;
/*     */ import java.awt.event.WindowAdapter;
/*     */ import java.awt.event.WindowEvent;
/*     */ import java.io.BufferedOutputStream;
/*     */ import java.io.BufferedReader;
/*     */ import java.io.File;
/*     */ import java.io.FileNotFoundException;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.InputStream;
/*     */ import java.io.InputStreamReader;
/*     */ import java.io.OutputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.net.ConnectException;
/*     */ import java.net.MalformedURLException;
/*     */ import java.net.URL;
/*     */ import java.net.URLConnection;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import java.util.List;
/*     */ import javax.swing.BoxLayout;
/*     */ import javax.swing.JFrame;
/*     */ import javax.swing.JLabel;
/*     */ import javax.swing.JOptionPane;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JProgressBar;
/*     */ import javax.swing.plaf.basic.BasicProgressBarUI;
/*     */ 
/*     */ public class BseFileDownloader
/*     */ {
/*  12 */   public List<String> datesToRead = new ArrayList();
/*  13 */   private List<String> datesInFile = new ArrayList();
/*  14 */   private List<String> datesToDelete = new ArrayList();
/*     */   private JLabel dloadStatus;
/*     */   private JFrame dloadFrame;
/*     */   private JPanel dloadPanel;
/*     */   private JProgressBar pbar;
/*     */ 
/*     */   private void buildDloadFrame()
/*     */   {
/*  31 */     this.dloadFrame = new JFrame("ProfitIndicators V2.05");
/*  32 */     this.dloadFrame.addWindowListener(new WindowAdapter()
/*     */     {
/*     */       public void windowClosing(WindowEvent paramWindowEvent)
/*     */       {
/*  36 */         System.out.println("Application launch terminated.");
/*  37 */         System.exit(0);
/*     */       }
/*     */     });
/*  41 */     this.dloadFrame.setResizable(false);
/*     */ 
/*  43 */     this.dloadPanel = new JPanel();
/*  44 */     this.dloadPanel.setLayout(new BorderLayout());
/*     */ 
/*  46 */     this.dloadStatus = new JLabel(" Downloading BSE Files. Please wait...");
/*     */ 
/*  48 */     this.pbar = new JProgressBar();
/*  49 */     this.pbar.setMinimum(1);
/*  50 */     this.pbar.setMaximum(310);
/*  51 */     this.pbar.setBackground(Color.WHITE);
/*  52 */     BasicProgressBarUI local2 = new BasicProgressBarUI() {
/*     */       protected Color getSelectionBackground() {
/*  54 */         return Color.black;
/*     */       }
/*     */       protected Color getSelectionForeground() {
/*  57 */         return Color.black;
/*     */       }
/*     */     };
/*  60 */     this.pbar.setUI(local2);
/*  61 */     this.pbar.setFont(new Font("Sanserif", 0, 12));
/*  62 */     this.pbar.setStringPainted(true);
/*     */ 
/*  64 */     JPanel localJPanel = new JPanel();
/*  65 */     localJPanel.setLayout(new BoxLayout(localJPanel, 3));
/*     */ 
/*  67 */     this.dloadFrame.add(this.dloadPanel);
/*  68 */     localJPanel.add(this.dloadStatus);
/*  69 */     localJPanel.add(new JLabel(" "));
/*  70 */     localJPanel.add(new JLabel(" Note:Launching for BSE first time in your system"));
/*  71 */     localJPanel.add(new JLabel(" will take some time to download the files depending"));
/*  72 */     localJPanel.add(new JLabel(" upon your connection speed. "));
/*  73 */     localJPanel.add(new JLabel(" "));
/*     */ 
/*  75 */     this.dloadPanel.add(localJPanel, "North");
/*  76 */     this.dloadPanel.add(this.pbar, "Center");
/*     */ 
/*  78 */     this.dloadFrame.setSize(350, 155);
/*  79 */     this.dloadFrame.setLocationRelativeTo(null);
/*  80 */     this.dloadFrame.setVisible(true);
/*     */   }
/*     */ 
/*     */   private void setupPath()
/*     */   {
/*  87 */     File localFile = new File("C:\\profitindicators");
/*  88 */     if (!localFile.exists()) {
/*  89 */       localFile.mkdir();
/*     */     }
/*  91 */     localFile = new File("C:\\profitindicators\\data");
/*  92 */     if (!localFile.exists()) {
/*  93 */       localFile.mkdir();
/*     */     }
/*  95 */     localFile = new File("C:\\profitindicators\\data\\bse");
/*  96 */     if (!localFile.exists()) {
/*  97 */       localFile.mkdir();
/*     */     }
/*  99 */     localFile = new File("C:\\profitindicators\\data\\userdata");
/* 100 */     if (!localFile.exists())
/* 101 */       localFile.mkdir();
/*     */   }
/*     */ 
/*     */   public void downloadFiles()
/*     */   {
/* 108 */     buildDloadFrame();
/* 109 */     readDates();
/* 110 */     this.pbar.setMaximum(this.datesInFile.size());
/* 111 */     readDatesToDelete();
/* 112 */     setupPath();
/*     */ 
/* 116 */     System.out.println("Downloading files for BSE...");
/*     */     String str;
/*     */     File localFile;
/* 117 */     for (int i = 0; i < this.datesInFile.size(); i++)
/*     */     {
/* 119 */       str = "C:\\profitindicators\\data\\bse\\eq" + (String)this.datesInFile.get(i) + ".zip";
/*     */ 
/* 121 */       localFile = new File(str);
/*     */ 
/* 123 */       if (!localFile.exists()) {
/*     */         try
/*     */         {
/* 126 */           fileDownloader(i, str);
/*     */         }
/*     */         catch (Exception localException1) {
/* 129 */           break;
/*     */         }
/*     */       }
/* 132 */       else if (localFile.length() < 20000L) {
/*     */         try
/*     */         {
/* 135 */           fileDownloader(i, str);
/*     */         }
/*     */         catch (Exception localException2) {
/* 138 */           break;
/*     */         }
/*     */       }
/*     */       else
/*     */       {
/* 143 */         this.datesToRead.add(this.datesInFile.get(i));
/*     */       }
/*     */ 
/* 147 */       this.pbar.setValue(i);
/*     */     }
/*     */ 
/* 152 */     System.out.println("Deleting old files...");
/* 153 */     for (int i = 0; i < this.datesToDelete.size(); i++)
/*     */     {
/* 155 */       str = "C:\\profitindicators\\data\\bse\\eq" + (String)this.datesToDelete.get(i) + ".zip";
/* 156 */       localFile = new File(str);
/*     */ 
/* 158 */       if (!localFile.exists())
/*     */         continue;
/*     */       try {
/* 161 */         localFile.delete();
/*     */       }
/*     */       catch (Exception localException3) {
/* 164 */         System.out.println("Failed to delete " + (String)this.datesToDelete.get(i) + ".zip");
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 171 */     this.dloadFrame.dispose();
/*     */   }
/*     */ 
/*     */   private void fileDownloader(int paramInt, String paramString)
/*     */     throws Exception
/*     */   {
/* 181 */     Boolean localBoolean = Boolean.valueOf(true);
/* 182 */     int i = 1;
/* 183 */     String str = "http://www.bseindia.com/bhavcopy/eq" + (String)this.datesInFile.get(paramInt) + "_csv.zip";
/*     */ 
/* 185 */     while (localBoolean.booleanValue()) {
/* 186 */       localBoolean = Boolean.valueOf(false);
/*     */ 
/* 188 */       BufferedOutputStream localBufferedOutputStream = null;
/* 189 */       URLConnection localURLConnection = null;
/* 190 */       InputStream localInputStream = null;
/*     */ 
/* 193 */       ArrayList localArrayList1 = new ArrayList();
/* 194 */       ArrayList localArrayList2 = new ArrayList();
/*     */       try
/*     */       {
/* 201 */         URL localURL = new URL(str);
/*     */ 
/* 203 */         localURLConnection = localURL.openConnection();
/* 204 */         localInputStream = localURLConnection.getInputStream();
/* 205 */         byte[] arrayOfByte = new byte[1024];
int j;
/*     */ 
/* 207 */         while ((j = localInputStream.read(arrayOfByte)) != -1) {
/* 208 */           localArrayList1.add(arrayOfByte.clone());
/* 209 */           localArrayList2.add(Integer.valueOf(j));
/*     */         }
/*     */ 
/* 213 */         localInputStream = localURL.openStream();
/* 214 */         j = localInputStream.read(arrayOfByte);
/*     */ 
/* 216 */         if (!Arrays.equals(arrayOfByte, (byte[])(byte[])localArrayList1.get(0)))
/*     */         {
/* 219 */           throw new FileNotFoundException();
/*     */         }
/*     */ 
/* 223 */         if (localArrayList1.size() < 20)
/*     */         {
/* 227 */           throw new FileNotFoundException();
/*     */         }
/*     */ 
/* 231 */         localBufferedOutputStream = new BufferedOutputStream(new FileOutputStream(paramString));
/*     */ 
/* 233 */         for (int k = 0; k < localArrayList1.size(); k++)
/*     */         {
/* 235 */           localBufferedOutputStream.write((byte[])(byte[])localArrayList1.get(k), 0, ((Integer)localArrayList2.get(k)).intValue());
/*     */         }
/*     */ 
/* 239 */         this.datesToRead.add(this.datesInFile.get(paramInt));
/*     */       }
/*     */       catch (FileNotFoundException localException2)
/*     */       {
/* 247 */         if (paramInt < this.datesInFile.size() - 10)
/*     */         {
/* 252 */           if (i == 1) {
/* 253 */             System.out.println("BSE EOD File not found in server for " + (String)this.datesInFile.get(paramInt) + ". Checking alternate source.");
/* 254 */             localBoolean = Boolean.valueOf(true);
/* 255 */             i = 2;
/* 256 */             str = "http://www.bseindia.com/Hisbhav/eq" + (String)this.datesInFile.get(paramInt) + "_csv.zip";
/*     */           } else {
/* 258 */             System.out.println("BSE EOD File not found in server for " + (String)this.datesInFile.get(paramInt));
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/*     */       }
/*     */       catch (ConnectException localConnectException)
/*     */       {
/* 268 */         JOptionPane.showMessageDialog(null, "Connection broken while downloading " + (String)this.datesInFile.get(paramInt), null, 0);
/*     */ 
/* 272 */         throw localConnectException;
/*     */       }
/*     */       catch (Exception localException3)
/*     */       {
/* 277 */         JOptionPane.showMessageDialog(null, "Unable to download EOD file for " + (String)this.datesInFile.get(paramInt) + ". \n" + "Check the folder \"C:\\profitindicators\\data\\bse\" not to be write protected \n" + "Check your internet connection", null, 0);
/*     */ 
/* 283 */         localException3.printStackTrace();
/* 284 */         throw localException3;
/*     */       }
/*     */       finally
/*     */       {
/*     */         try
/*     */         {
/* 292 */           if (localInputStream != null) {
/* 293 */             localInputStream.close();
/*     */           }
/* 295 */           if (localBufferedOutputStream != null) {
/* 296 */             localBufferedOutputStream.close();
/*     */           }
/*     */         }
/*     */         catch (Exception localException4)
/*     */         {
/* 301 */           localException4.printStackTrace();
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private void readDatesToDelete()
/*     */   {
/*     */     try
/*     */     {
/* 317 */       URL localURL = new URL("http://www.profitindicators.com/home/bseDeleteFls.csv");
/*     */ 
/* 319 */       InputStream localInputStream = localURL.openStream();
/* 320 */       BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localInputStream));
/*     */ 
/* 322 */       String str = localBufferedReader.readLine();
/* 323 */       str = localBufferedReader.readLine();
/*     */ 
/* 325 */       while (str != null)
/*     */       {
/* 327 */         this.datesToDelete.add(str.trim());
/*     */ 
/* 329 */         str = localBufferedReader.readLine();
/*     */       }
/*     */ 
/* 333 */       localBufferedReader.close();
/*     */     }
/*     */     catch (FileNotFoundException localFileNotFoundException)
/*     */     {
/* 338 */       System.out.println("File deleteFiles.csv not found.");
/*     */     }
/*     */     catch (MalformedURLException localMalformedURLException)
/*     */     {
/* 342 */       System.out.println("URL malformed");
/* 343 */       localMalformedURLException.printStackTrace();
/*     */     }
/*     */     catch (Exception localException)
/*     */     {
/* 347 */       localException.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   private void readDates()
/*     */   {
/*     */     try
/*     */     {
/* 358 */       URL localURL = new URL("http://www.profitindicators.com/home/bseDts.csv");
/*     */ 
/* 360 */       InputStream localInputStream = localURL.openStream();
/* 361 */       BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localInputStream));
/*     */ 
/* 363 */       String str = localBufferedReader.readLine();
/* 364 */       str = localBufferedReader.readLine();
/*     */ 
/* 366 */       while (str != null)
/*     */       {
/* 368 */         this.datesInFile.add(str.trim());
/*     */ 
/* 370 */         str = localBufferedReader.readLine();
/*     */       }
/*     */ 
/* 374 */       localBufferedReader.close();
/*     */     }
/*     */     catch (FileNotFoundException localFileNotFoundException)
/*     */     {
/* 379 */       System.out.println("File dates.csv not found.");
/*     */     }
/*     */     catch (MalformedURLException localMalformedURLException)
/*     */     {
/* 383 */       System.out.println("URL malformed");
/* 384 */       localMalformedURLException.printStackTrace();
/*     */     }
/*     */     catch (Exception localException)
/*     */     {
/* 388 */       localException.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public static void main(String[] paramArrayOfString)
/*     */   {
/* 397 */     BseFileDownloader localBseFileDownloader = new BseFileDownloader();
/*     */ 
/* 399 */     localBseFileDownloader.downloadFiles();
/* 400 */     System.out.println("datesInFile");
/* 401 */     System.out.println("" + localBseFileDownloader.datesInFile.size());
/* 402 */     System.out.println("" + (String)localBseFileDownloader.datesInFile.get(0));
/* 403 */     System.out.println("" + (String)localBseFileDownloader.datesInFile.get(localBseFileDownloader.datesInFile.size() - 1));
/*     */ 
/* 405 */     System.out.println("datesToDelete");
/* 406 */     System.out.println("" + localBseFileDownloader.datesToDelete.size());
/* 407 */     System.out.println("" + (String)localBseFileDownloader.datesToDelete.get(0));
/* 408 */     System.out.println("" + (String)localBseFileDownloader.datesToDelete.get(localBseFileDownloader.datesToDelete.size() - 1));
/*     */ 
/* 410 */     System.out.println("datesToRead");
/* 411 */     System.out.println("" + localBseFileDownloader.datesToRead.size());
/* 412 */     System.out.println("" + (String)localBseFileDownloader.datesToRead.get(0));
/* 413 */     System.out.println("" + (String)localBseFileDownloader.datesToRead.get(localBseFileDownloader.datesToRead.size() - 1));
/*     */   }
/*     */ }

/* Location:           C:\Users\Deebak\Downloads\profitindicatorsv2-05.jar
 * Qualified Name:     BseFileDownloader
 * JD-Core Version:    0.6.0
 */